﻿#ifndef NSA3000TWTF_H
#define NSA3000TWTF_H

#include <QtCore/qglobal.h>

#if defined(NSA3000TWTF_LIBRARY)
#  define NSA3000TWTFSHARED_EXPORT Q_DECL_EXPORT
#else
#  define NSA3000TWTFSHARED_EXPORT Q_DECL_IMPORT
#endif

#include "sys_h/SYS_VER.h"
#include "sys_h/DATATYPE.h"
#include "sys_h/DATATYPE_S.h"
#include "db_h/TABLEDEF.h"
#include "sys_h/SYS_DATA.h"
#include "order_h/DATA_ORDER_NUM.h"
#include "seq_define.h"
#include "db_h/hTableDef.h"

#include "db_h/NSA3000TDB.h"
#include "sh_m_h/NSA3000TRD.h"
#include "sh_m_h/NSA3000TSS.h"
#include "sh_m_h/NSA3000TNM.h"
#include "order_h/SYS_ORDER_NUM.h"

typedef XCHAR   CHAR;
typedef XUCHAR  UCHAR;
typedef XINT    INT;
typedef unsigned int UINT;
typedef unsigned char  BYTE;

using namespace std;
#include <algorithm>
#include <functional>
#include <vector>


class NSA3000TWTFSHARED_EXPORT NSA3000TWTF
{
public:
	NSA3000TWTF();
	XINT init_wtf_dll();
	void free_wtf_dll();
	//逆波兰
	void InitStack (SqStack *S);//建栈 
	void DeleteStack (SqStack *S);//清内存
	int  Push(SqStack *S,char ch);//进栈 
	int  Pop(SqStack *S,char *ch);//出栈
	XBOOL8 Translate(QString org,QString &sret,QString &MsgStr);

	

	XINT   ReadModelFile(int modeltype,int unittype,int seqtype,LIST_Wf_Model &model_list);
	XBOOL8 Write_ticket_File(LIST_Wf_Ticket step_list,int tickettype,int unittype,int unit_id,int dev_id,int seqtype);
	XBOOL8 Write_seq_ticket_File(WF_SeqHead seq_head, LIST_Seq_Ticket step_list,LIST_seq_erroryx erroryx_list, int tickettype,int unittype,int unit_id,int dev_id,int seqtype,XBOOL8 bercipiao=false,QString serciseqname="");
	XBOOL8 Write_seq_erci_ticket_File(WF_SeqHead seq_head, LIST_Seq_Ticket step_list,LIST_seq_erroryx erroryx_list, QString serciseqname);
	XBOOL8 Write_seq_xml_ticket_File(WF_SeqHead seq_head, LIST_Seq_Ticket step_list,LIST_seq_erroryx erroryx_list, int tickettype,int unittype,int unit_id,int dev_id,int seqtype);
	XBOOL8 Write_seq_xml_erci_ticket_File(WF_SeqHead seq_head, LIST_Seq_Ticket step_list,LIST_seq_erroryx erroryx_list, QString serciname);

	XBOOL8 Write_other_ticket_File(LIST_Wf_Ticket ticket_list,int tickettype,QString sfilename);
	XINT Read_other_ticket_File(QString sfilename,LIST_Wf_Ticket &seq_ticket_list);
	QString Get_ticket_name_by_seqtype(int tickettype,int unit_id,int devadd,int seqtypet);
	QString Get_ticket_name_erci_by_erciname(int tickettype,QString serciname);
	QString Get_ticket_name_no_path_by_seqtype(int tickettype,int unit_id,int dev_add,int seqtypet);
	XINT  Read_seq_erci_ticket_File(QString sercifilename,WF_SeqHead &seq_head, LIST_Seq_Ticket &step_list,LIST_seq_erroryx &erroryx_list);
	XINT  Read_seq_ticket_File(int tickettype,int unittype,int unit_id,int dev_id,int seqtype,WF_SeqHead &seq_head, LIST_Seq_Ticket &step_list,LIST_seq_erroryx &erroryx_list);
	XINT  Read_dx_ticket_File(int tickettype,int unittype,int unit_id,int dev_id,int seqtype,LIST_Wf_Ticket &dx_ticket_list);

	XINT  Read_dx_ticket_File_by_filename(QString sfilename,LIST_Wf_Ticket &dx_ticket_list);

	XINT  Delete_ticket_File(int tickettype,int unittype,int unit_id,int dev_id,int seqtype);



	XBOOL8 vdInsertOneWFOpertate(LIST_Wf_Ticket &wf_ticket ,DATA_LINK pObj,CHAR start_state,CHAR end_state,rWf_Yx_Info wf_param_yx,XBOOL8 bBeginLinkOpre=FALSE,XBOOL8 bIsInLinkOpre=FALSE,XBOOL8 bNeedDialog=FALSE);

	XBOOL8 bTransact_Not_DX(DATA_LINK pObj,CHAR start_state,CHAR end_state,rWf_Yx_Info wf_param_yx);

	XBOOL8 bTransact_Pre_prompt(LIST_Wf_Ticket &wf_ticket ,DATA_LINK pObj,CHAR state,CHAR start_state,CHAR end_state,rWf_Yx_Info wf_param_yx,XBOOL8 bBeginLinkOpre,XBOOL8 bIsInLinkOpre,XBOOL8 bNeedDialog);


	XBOOL8 bTransact_Operate_DuanYu(LIST_Wf_Ticket &wf_ticket ,DATA_LINK pObj,CHAR state,CHAR start_state,CHAR end_state,rWf_Yx_Info wf_param_yx,int selected_groundline_id,XBOOL8 bBeginLinkOpre,XBOOL8 bIsInLinkOpre,XBOOL8 bNeedDialog);
	XBOOL8 bSeq_Transact_Operate_DuanYu(LIST_Seq_Ticket &seq_ticket ,DATA_LINK pObj,CHAR state,CHAR start_state,CHAR end_state,rWf_Yx_Info wf_param_yx);

	XBOOL8 bTransact_After_Prompt(LIST_Wf_Ticket &wf_ticket ,DATA_LINK pObj,CHAR state,CHAR start_state,CHAR end_state,rWf_Yx_Info wf_param_yx,XBOOL8 bBeginLinkOpre,XBOOL8 bIsInLinkOpre,XBOOL8 bNeedDialog);
	XBOOL8 vdAddNewTicketItem(LIST_Wf_Ticket &wf_ticket ,int ticket_type,DATA_LINK db_link,CHAR *szContent,CHAR before_state,CHAR type,CHAR start_state,CHAR end_state,XBOOL8 is_linkage_oper_begin,CHAR *sVerb,CHAR lock_type,XUSHORT lock_addr,int wf_dev_type,XBOOL8 bIsInLinkAgeOper,XBOOL8 bIsOperateGroundLine=FALSE,int groundLine_id=0,XBOOL8 isUse=TRUE);
	
	XBOOL8 vdAddNew_Seq_TicketItem(LIST_Seq_Ticket &seq_ticket,DATA_LINK db_link,CHAR *szContent,CHAR type,CHAR start_state,CHAR end_state,CHAR *sVerb);


	QString Get_unit_state_filename(int devadd);
	XINT    Read_Unit_State_File(int devadd,SEQ_DEVSTATE_FILE &Dev_State_File);
	XBOOL8  Write_Unit_State_File(int devadd,SEQ_DEVSTATE_FILE Dev_State_File);


	XINT  Read_Unit_jx_type_File(LIST_Wf_Unit_Jx_Type_Set &model_list);
	XBOOL8  Write_Unit_jx_type_File(LIST_Wf_Unit_Jx_Type_Set model_list);

	XBOOL8 DeleteDirectory(QString &DirName);
	XBOOL8 DeleteFile_by_devadd(QString &DirName,vector<int> unitid);
	XBOOL8 GetFileInDirectory(QString &DirName,QStringList &stieketfilelist);
	void Get_wf_o_type_dsp(WF_Model pwf_o_type,QString &stype,QString &soper);
	void Get_wf_math_FH(XBYTE yc_compare,QString &stype);

	QString GetCompareFH(int yc_fh);

	//顺控
	QString Get_seq_dz_type(XINT dz_type);
	QString Get_seq_attribute_type(XINT dz_type);
	QString Get_seq_error_type(XINT dz_type);

	//五防规则

	//XINT  WriteRuleRecord(rWf_Rule_Info pRule);
	//XINT  DeleteRuleByDevbyname_Indexno(char *DevByname,int indexno);

	
	XINT Contruct_seq_rule_info(DATA_LINK db_link,int start_state,int end_state,SEQ_DATA_LINK*& pseq_datalink_struct,QString &snbl);

	int  DataLink_to_SeqDataLink(DATA_LINK db_link,SEQ_DATA_LINK & seq_data_link);
	int  DataLink_to_YkDataLink(DATA_LINK db_link,SEQ_DATA_LINK & yk_data_link);

	XBOOL8 Create_seq_ticket_by_devid_and_seqtype(LIST_Seq_Ticket &list_seq_ticket,int dev_id,int seq_type);
	XBOOL8 Create_dx_ticket_by_devid_and_seqtype (LIST_Wf_Ticket &list_dx_ticket,int dev_id,int seq_type);


	//取描述
	QString  Get_name(int type,int data);
	int Get_unit_jx_type(int unit_type);


//----  以下画面移植-------
	int Check_Cur_dev_state(int dev_id);
	QString  Get_unit_state_dsp(int unitstate);
	bool Check_one_state(SEQ_EXE_CONFIG temp);


	XINT PreSet_dev_seq_state(int dev_id,int statevalue);

	XINT Clearwfstate_by_devid(int dev_id,int statevalue);
	XINT ReserveObjWFState_ByYxID(NSA3000TNM *pMsg_SM,NSA3000TRD *pRealDB,NSA3000TSS *pPro_State_SM,XUINT YXID,XUINT type );

	XINT SetWFYxStateAndOutputV(NSA3000TNM *pMsg_SM,NSA3000TRD *pRealDB,NSA3000TSS *pPro_State_SM,DATA_LINK db_link,XINT yx_state, XBYTE output_value);
    XINT send_modify_rd_net_msg(NSA3000TNM *pMsg_SM,NSA3000TRD *pRealDB,NSA3000TSS *pPro_State_SM,hEvent_Modify_RD *pmodi_rd);

	void Get_cur_need_seqtype(int dev_id,int dev_state,vector<int >& seqtype);
	QString  Get_unit_seqtype_dsp(int seqtype);

};

#endif // NSA3000TWTF_H
